package com.apisix.service.controller;

import java.security.MessageDigest;

public class AppTest {
    public static void main(String[] args) throws Exception {
        // 生成当前时间戳
        String timestamp = String.valueOf(System.currentTimeMillis());
        System.out.println(timestamp);
        // 计算授权签名（app_secret+时间戳的MD5哈希值）
        String authorization = getMD5Hash("password123" + timestamp);
        System.out.println(authorization);
    }

    /**
     * 计算字符串的MD5哈希值（大写）
     */
    private static String getMD5Hash(String input) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] hashBytes = md.digest(input.getBytes("UTF-8"));

        StringBuilder sb = new StringBuilder();
        for (byte b : hashBytes) {
            sb.append(String.format("%02X", b));
        }

        return sb.toString();
    }
}
